package com.xbongbong.pro.enums.cloudcode.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 云叩控件
 * 创建时间 2020/9/21 2:48 PM
 * 修改时间 2020/9/21 2:48 PM
 * @author chy
 */
@Getter
public enum CloudCodeControlEnum {

    /**
     * 云叩控件枚举类
     */
    MENU(0, "自定义菜单"),
    BUTTON_LIST(1, "列表页按钮"),
    BUTTON_DETAIL(2, "详情页按钮"),
    TAB(3, "TAB"),
    CARD_LEFT(4, "首页卡片-左侧"),
    CARD_RIGHT(5, "首页卡片-右侧"),
    UNKNOWN(404, "未知类型"),

    ;

    private Integer code;

    private String name;


    CloudCodeControlEnum(Integer code, String name){
        this.code = code;
        this.name = name;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static CloudCodeControlEnum getByCode(Integer code) {
        for (CloudCodeControlEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getCode(), code)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }
}
